package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.Ticket;
import com.ruoyi.system.mapper.TicketDao;
import com.ruoyi.system.service.TicketService;
import org.springframework.stereotype.Service;

/**
 * Auto created by codeAppend plugin
 */
@Service
public class TicketServiceImpl extends ServiceImpl<TicketDao, Ticket> implements TicketService {
    @Override
    public boolean createTicket(Ticket ticket) {
        Ticket t = new Ticket();
        t.setScenic(ticket.getScenic());
        t.setType(ticket.getType());
        t.setPrice(ticket.getPrice());
        return baseMapper.insert(t) > 0;
    }

    @Override
    public Ticket getTicketById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public boolean updateTicket(Ticket ticket) {
        LambdaQueryWrapper<Ticket> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Ticket::getId, ticket.getId());
        Ticket t = baseMapper.selectOne(lqw);
        if (t == null){
            throw new RuntimeException("Ticket not found");
        }
        t.setScenic(ticket.getScenic());
        t.setType(ticket.getType());
        t.setPrice(ticket.getPrice());
        return baseMapper.updateById(t) > 0;
    }

    @Override
    public boolean deleteTicket(Long id) {
        return baseMapper.deleteById(id) > 0;
    }

    // use "baseMapper" to call jdbc
    // example: baseMapper.insert(entity);
    // example: baseMapper.selectByPage(params);

}
